package com.btobtob.a.biz.user.controller;

import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.cola.dto.SingleResponse;
import com.btobtob.a.biz.user.actor.DemoJActor;

import io.dapr.actors.ActorId;
import io.dapr.actors.client.ActorClient;
import io.dapr.actors.client.ActorProxyBuilder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Slf4j
@RestController
@Tag(name = "actor", description = "actor")
@RequestMapping("/actor")
@Validated
public class ActorController {

    private static final Logger logger = LoggerFactory.getLogger(ActorController.class);

    @Resource
    private ActorClient actorClient;

    @Operation(summary = "test1", tags = "actor")
    @GetMapping(value = "/test1")
    public SingleResponse<String> test1() {

//        try {
        ActorProxyBuilder<DemoJActor> builder = new ActorProxyBuilder<>(DemoJActor.class, actorClient);

        DemoJActor demoJActor1 = builder.build(new ActorId("1"));

        int index = 1;

        // First, register reminder.
//        demoActor1.registerReminder(index);
        // Second register timer.
//        demoActor1.registerTimer("ping! {" + index + "} ");

        Integer v1 = demoJActor1.incrementAndGet(1).block();
        String message1 = String.format("Message #%d received from actor at with ID %s", v1, 1);
        String result1 = demoJActor1.say(message1);
        logger.info(result1);
        return SingleResponse.of(result1);
//        }
    }
    
}
